from pydantic import BaseModel, ConfigDict, Field
from typing import Optional, List
from datetime import datetime


class RoleBase(BaseModel):
    id: str = Field(default=None, max_length=32, description="用户ID")
    description: Optional[str] = Field(default=None, max_length=50, description="用户邮箱")
    name: str = Field(default=None, min_length=1, max_length=50, description="登录名")
    tenant_id: str = Field(default=None, min_length=1, max_length=32, description="租户ID")
    created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
    updated_at: datetime = Field(default_factory=datetime.now, description="更新时间")


class RoleCreate(RoleBase):
    pass


class RoleUpdate(RoleBase):
    description: Optional[str] = Field(default=None, max_length=50, description="用户邮箱")
    name: str = Field(default=None, min_length=1, max_length=50, description="登录名")


class RoleInDBBase(RoleBase):
    id: str
    name: str
    description: str
    created_at: datetime
    updated_at: datetime

    model_config = ConfigDict(from_attributes=True)


class Role(RoleInDBBase):
    pass


class RoleInDB(RoleInDBBase):
    pass


# 用户角色关联相关
class UserRoleAssign(BaseModel):
    role_ids: List[str]


class RoleUserAssign(BaseModel):
    user_ids: List[str]
